/**
 * Created by Administrator on 2016/3/25.
 */

        // 基于准备好的dom，初始化echarts实例
$(function(){
    $('#monthCon1').width($('.container').width());
    $.get('/business/financial/cashier?action=salemapjson&searchTime=1',function(data){
        var monthArr =[],
            val = [];
        $.each(data,function(i,o){
            monthArr.push(i);
            val.push(o);
        });
        function tranN(x){
            if(x==null){
                return 0;
            } else {
                return x;
            }
        }
        var val2 = val.map(tranN);
        var myChart3 = echarts.init(document.getElementById('monthCon'));

        // 指定图表的配置项和数据
        var oridata = val2;
        var data0 = [];
        for (var i = 0, l = oridata.length; i < l; i++) {
            total = oridata[i];
            data0.push(Math.round(total * 1));
        }

        var option3 = {

            grid:{
                width:'90%',
                left:40,
                containLabel:true,
            },
            calculable : true,
            xAxis : [
                {
                    name:'时间',
                    type : 'category',
                    splitLine: {
                        show: false
                    },
                    nameTextStyle: {
                        color:'#878DA1' ,
                        fontSize:'13px',
                    },
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color: '#e5e5e5'
                        }
                    },
                    axisTick: {
                        show:false
                    },
                    data : monthArr
                }
            ],
            yAxis : [
                {
                    name:'营业收入',
                    type : 'value',
                    min: 0,
                    /* max: 2500,
                     interval: 250,*/
                    nameTextStyle: {
                        color:'#878DA1' ,
                        fontSize:'13px',
                    },
                    nameGap:'25',
                    axisLine: {
                        show:false,
                        lineStyle: {
                            color: '#e5e5e5'
                        }
                    },
                    axisTick: {
                        show:false
                    },
                    splitLine: {
                        lineStyle:{
                            type:'dashed'
                        }
                    },
                    splitArea : {show : false}
                }
            ],
            series : [

                {
                    name:'1',
                    type:'bar',
                    barWidth:35,
                    stack: '广告',
                    barMinHeight:5,
                    label: {
                        normal: {
                            show: true,
                            formatter: '{c}',
                            position: 'top',
                            textStyle:{
                                color:'#6f6f6f',
                            }
                        }
                    },
                    barCategoryGap:'10%',
                    itemStyle: {
                        normal: {
                            show:false,
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 0.8, [{
                                offset: 0,
                                color: '#f78ca8'
                            }, {
                                offset: 1,
                                color: '#fce5a2'
                            }])
                        }
                    },

                    data:data0,

                },
            ]

        };

        myChart3.setOption(option3);

    },'json');

    (function(){
        $.get('/business/financial/cashier?action=salemapjson&searchTime=2',function(data){

            var monthArr =[],
                val = [];
            $.each(data,function(i,o){
                monthArr.push(i);
                val.push(o);
            });
            function tranN(x){
                if(x==null){
                    return 0;
                } else {
                    return x;
                }
            }
            var val2 = val.map(tranN);

            var myChart4 = echarts.init(document.getElementById('monthCon1'));

            // 指定图表的配置项和数据
            var oridata = val2;
            var data0 =[]

            var total;
            for (var i = 0, l = oridata.length; i < l; i++) {
                total = oridata[i];
                data0.push(Math.round(total * 1));
            }
            var option4 = {
                legend:{
                    show: false,
                },
                grid:{
                    width:'90%',
                    left:40,
                    containLabel:true,
                },
                calculable : true,
                xAxis : [
                    {
                        name:'时间',
                        type : 'category',
                        splitLine: {
                            show: false
                        },
                        nameTextStyle: {
                            color:'#878DA1' ,
                            fontSize:'14px',
                        },
                        nameGap:'25',
                        axisLine: {
                            show:false,
                            lineStyle: {
                                color: '#e5e5e5'
                            }
                        },
                        axisTick: {
                            show:false
                        },
                        data : monthArr
                    }
                ],
                yAxis : [
                    {
                        name:'营业收入',
                        type : 'value',
                        min: 0,
                        /*max: 2500,
                         interval: 250,*/
                        nameTextStyle: {
                            color:'#878DA1' ,
                            fontSize:'14px',
                        },
                        barMinHeight:'44',
                        nameGap:'25',
                        axisLine: {
                            show:false,
                            lineStyle: {
                                color: '#e5e5e5'
                            }
                        },
                        splitLine: {
                            lineStyle:{
                                type:'dashed'
                            }
                        },
                        axisTick: {
                            show:false
                        },
                    }
                ],
                series : [
                    {
                        name:'1',
                        type:'bar',
                        barWidth:35,
                        stack: '广告',
                        barCategoryGap:'10%',
                        barMinHeight:5,
                        label: {
                            normal: {
                                show: true,
                                formatter: '{c}',
                                position: 'top',
                                textStyle:{
                                    color:'#6f6f6f'
                                }
                            }
                        },
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.8, [{
                                    offset: 0,
                                    color: '#f78ca8'
                                }, {
                                    offset: 1,
                                    color: '#fce5a2'
                                }])
                            },
                            emphasis: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 0.8, [{
                                    offset: 0,
                                    color: '#f78ca8'
                                }, {
                                    offset: 1,
                                    color: '#fce5a2'
                                }])
                            }

                        },
                        data:data0
                    }
                ]

            };
            myChart4.setOption(option4);

        },'json')
    })()
})


